package com.ran.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ran.reggie.common.R;
import com.ran.reggie.entity.Employee;
import com.ran.reggie.entity.Orders;
import com.ran.reggie.service.impl.OrderService;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {
	/**
	 * 分页查询
	 */
    @Autowired
    private OrderService orderService;
    @GetMapping("/page")
    public R<Page> page(int page,int pageSize,String number,Date beginTime,Date endTime){
    	log.info("page = {},pageSize = {},number = {}",page,pageSize,number);
    	Page pageInfo = new Page(page, pageSize);
    	//条件构造器
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        //添加过滤条件
        queryWrapper.between(Orders::getOrderTime , beginTime,endTime).like(Orders::getNumber,number);
        //添加排序条件
        queryWrapper.orderByDesc(Orders::getOrderTime);
        //执行查询
        orderService.page(pageInfo,queryWrapper);
        return  R.success(pageInfo);
    }
    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("订单数据：{}",orders);
        orderService.submit(orders);
        return R.success("下单成功");
    }
}
